package com.liaoban.app;

import android.app.Activity;
import android.content.Intent;

import com.liaoban.app.api.manager.HttpManager;
import com.liaoban.app.constants.Constant;
import com.liaoban.app.constants.HttpConstant;
import com.liaoban.app.service.LocationService;
import com.liaoban.app.ui.StartActivity;
import com.liaoban.app.ui.WelcomeActivity;
import com.liaoban.app.util.CommonUtils;
import com.netease.nim.demo.NimApplication;
import com.umeng.commonsdk.UMConfigure;
import com.umeng.socialize.PlatformConfig;

import cn.jpush.android.api.JPushInterface;


/**
 * Created by ybc on 2017/9/11.
 */

public class App extends NimApplication {
    private static App sInstance;

    public static App getInstance() {
        return sInstance;
    }

    @Override
    public void onCreate() {
        sInstance = this;
        START_ACTIVITY_CLASS = WelcomeActivity.class;
        super.onCreate();
        String env = CommonUtils.getMeta(this, HttpConstant.HTTP_API_ENV);
        boolean isDebug = !HttpConstant.HTTP_API_ENV_RELEASE.equals(env);
        isDebug = true; // TODO: 2017/9/27 0027 开发时都打开
        HttpManager.getInstance().init(this, env);
        initUm(isDebug);
        startService(new Intent(this, LocationService.class));
        JPushInterface.setDebugMode(true);    // 设置开启日志,发布时请关闭日志
        JPushInterface.init(this); // 初始化 JPush
    }

    /**
     * 友盟统计和社会化初始化
     */
    private void initUm(boolean isDebug) {
        UMConfigure.setLogEnabled(isDebug);
        /**
         * 初始化common库
         * 参数1:上下文，不能为空
         * 参数2:设备类型，UMConfigure.DEVICE_TYPE_PHONE为手机、UMConfigure.DEVICE_TYPE_BOX为盒子，默认为手机
         * 参数3:Push推送业务的secret
         */
        UMConfigure.init(this, UMConfigure.DEVICE_TYPE_PHONE, "");
        PlatformConfig.setWeixin(Constant.WEIXIN_APPID, Constant.WEIXIN_SECRET);
        //豆瓣RENREN平台目前只能在服务器端配置
        PlatformConfig.setSinaWeibo(Constant.SINA_APPID, Constant.SINA_SECRET, "http://sns.whalecloud.com");
        PlatformConfig.setQQZone(Constant.QQ_APPID, Constant.QQ_SECRET);
    }

}
